<template>
	<view>
		<view class="comment-box">
			<view class="comment-head">
				<view class="commit-title-left">
					<view class="icon iconfont" style="font-size: 38rpx;color: #333333;">&#xe619;</view>
					<view class="discuss">评论<text style="color: #c1c1c1;"></text></view>
				</view>
				<view class="commit-title-right">
					<!-- <image src="../../static/image/edit.png" mode="aspectFill"></image> -->
					<view class="icon iconfont" style="margin-right: 5rpx;font-size: 32rpx;color: #378aff;">&#xe695;</view>
					<view @click="commentshare">写评论</view>
				</view>
			</view>

			<view class="comment-info" v-for="(item,index) in commentlist" :key="index">
				<image class="avatar" :src="item.avatar" mode="aspectFill"></image>
				<view class="item-box">
					<view class="comment-item">
						<view class="comment-nickname">
							<text>{{item.nickname}}</text>
							<text class="fqtip" v-if="item.initiator">发起人</text>
							<!-- <text class="topping">置顶</text> -->
						</view>
						<view class="icon iconfont"  style="font-size: 45rpx;color: #333333" >&#xe701;</view>
					</view>

					<view class="comment-item">
						<text class="comment-more">{{item.content}}</text>
					</view>

					<view class="comment-item">
						<view class="comment-timer">{{item.add_time}}</view>
						<view class="comment-option">
							<view class="option-item" v-if="userinfo.id==initiator.id">
								<view class="icon iconfont">&#xe703;</view>
								<text @click="replayfollow(item.id,item.nickname)">回复</text>
							</view>
							<view class="option-item" @click="givelike(index)"> 
								<text>{{item.like}}</text>
								<view :class="['iconfont',item.my_like?'iconbg':'']" >&#xe702;</view>
							</view>
						</view>
					</view>

					<view class="faqirenhuifu" v-if="item.reply">
						<view class="auth">发起人：</view>
						<view class="huifu">{{item.reply}}</view>
					</view>
				</view>
			</view>
		
		</view>
	<view class="emptycomment">-- 没有更多评论 --</view>
		<!--评论操作-->
	<!-- 	<view class="share" :class="[animation?'moves':'selectedmove']">
			<view class="share-item" @click="deletecomment">
				<text>删除</text>
			</view>
			<view class="share-item" @click="topcomment">
				<text>置顶</text>
			</view>
			<view class="share-item" @click="showShare=false">
				<text  style="color: #bfbfbf;">取消</text>
			</view>
		</view> -->
	
		 
	</view>
</template>

<script>
	/*
	 * 用户评论插件
	 */
	export default {
		props:{
			initiator:{
				type:Object,
				default:{
					id:'',
				}
			},
			userinfo:{
				type:Object,
				default:{}
			},
			commentlist:{
				type:Array,
				default(){
					return []
				}
			}
		},
		watch: {
			showShare(value) {
				console.log(value);
				this.$nextTick(function() {
					this.animation = value;
				})
			}
		},
		data() {
			return {
				showShare: false,
				animation: false,
				
			}
		},
		mounted() {
		    let info = uni.createSelectorQuery().in(this).select('.comment-box').boundingClientRect()
		    info.exec(res => {
				console.log(res);
		        // this.scrollHeight = res[0].height
		        // console.log(this.scrollHeight)
		    })
		},
		methods: {
			//点赞
			givelike(index){
				if(this.$Logintip()){
					this.$Userlogin()
					return
				} 
				let ismylike = this.commentlist[index].my_like
				if(!ismylike){
					this.$HttRequest({
						url: '/lotteryComment/like',
						param: {id:this.commentlist[index].id}
					},"POST",true).then((res) => {
						if (res.status === 10000) {
							this.$ShowMsg('点赞成功!');
							this.$set(this.commentlist[index],'my_like',true);
							this.$set(this.commentlist[index],'like',parseInt( this.commentlist[index].like)+1);
						} else {
							this.$ShowMsg(res.message)
						}
					}).catch((error) => {
						//异常错误
						this.$ShowMsg('statusCode：' + error.errMsg);
					});
				}else{
					this.$ShowMsg('您已点赞！')
				}
			},
			
			 commentshare(){
				 if(this.$Logintip()){
				 	this.$Userlogin()
				 	return
				 } 
				this.$emit('replycomment')
			 },
			
			//跟随回复内容
			replayfollow(id,atwho){
				console.log(id);
				if(this.$Logintip()){
					this.$Userlogin()
					return
				} 
				this.$emit('replycomment',{id:id,atwho:atwho});
			},

			//删除
			deletecomment() {
				console.log('delete')
			},
			//置顶
			topcomment() {
				console.log('topcomment');
			},

			clear() {

			}
		}
	}
</script>

<style lang="scss">
	.emptycomment{
		width: 100%;
		color: #e6e6e6;
		text-align: center;
		font-size: 25rpx;
	}
	.comment-box {
		background-color: #fff;
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 20rpx;

	}
	.iconfont{
		color: #ababab;
		font-size: 28rpx;
	}
	.iconbg{
		color: $uni-color-primary;
	}
	.comment-info {
		flex: 1;
		justify-content: center;
		display: flex;
		align-items: flex-start;
		margin-top: 28rpx;

		.avatar {
			margin-right: 20rpx;
			width: 70rpx;
			height: 70rpx;
			border-radius: 50%;
		}

		.item-box {
			display: flex;
			justify-content: center;
			flex: 1;
			flex-direction: column;
			border-bottom: 1rpx solid #f0f0f0;

			.faqirenhuifu {
				display: flex;
				align-items: flex-start;
				justify-content: center;
				font-size: 28rpx;
				flex: 1;
				color: #000;
				background-color: #f7f7f7;
				padding: 20rpx;
				margin: 20rpx 0;

				.auth {
					flex: 1;
					color: $uni-color-primary;
				}

				.huifu {
					flex: 4;
				}

			}

			.comment-item {
				flex: 1;
				display: flex;
				align-items: center;

				justify-content: space-between;
				color: #ababab;
				font-size: 25rpx;
				margin-bottom: 10rpx;
				.comment-more {
					color: #4d4d4d;
					letter-spacing: 1rpx;
					font-size: 28rpx;
					margin: 10rpx 0;
				}

				.comment-timer {}

				.comment-option {
					display: flex;
					align-items: center;
					justify-content: center;

					.option-item {
						margin: 0 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}

				.comment-nickname {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 28rpx;
					color: #000;

					.fqtip {
						font-size: 18rpx;
						color: #fff;
						background-color: $uni-botton-primary;
						padding: 2rpx 10rpx;
						margin-left: 10rpx;
					}

					.topping {
						font-size: 18rpx;
						color: #fff;
						background-color: #c1c1c1;
						padding: 2rpx 10rpx;
						margin-left: 10rpx;
					}
				}

				.point {

					display: flex;
					align-items: flex-start;
					justify-content: flex-start;
				}
			}
		}

	}

	.comment-head {
		display: flex;
		justify-content: space-between;
		flex: 1;
		margin-bottom: 50rpx;

		.commit-title-left {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;

			.discuss {
				font-weight: bold;
				font-size: 30rpx;
				margin-left: 5rpx;
			}

			image {
				width: 30rpx;
				height: 30rpx;
			}
		}

		.commit-title-right {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 25rpx;
			color: $uni-color-primary;

			image {
				width: 30rpx;
				height: 30rpx;
			}
		}
	}

	//遮罩层
	.marsk {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		transition-property: opacity;
		transition-duration: 0.2s;
		opacity: 0;
		z-index: 990;
		background-color: #000;
	}

	.opacitytest {
		opacity: 0.5;
	}

	.moves {
		transform: translateY(0);
	}

	.selectedmove {
		transform: translateY(350rpx);
	}

	.share-botton {
		font-weight: bold;
		width: 80%;
		margin: 0 auto;
		height: 120rpx;
		background-color: #fff;
		border-radius: 20rpx;
		display: flex;
		font-size: 32rpx;
	}

	.yaoqing {
		margin-right: 15rpx;
	}

	.share-left {
		display: flex;
		flex-direction: column;
		color: #bc5300;
		background-color: #fdd2b0;
		justify-content: center;
		align-items: center;
		border-top-left-radius: 20rpx;
		border-bottom-left-radius: 20rpx;
		flex: 2;
	}

	.share-right {
		flex: 3;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #0f8cfa;
		font-size: 35rpx;
	}

	.copybg {
		background-color: #fd8425;
		font-size: 25rpx;
		color: #fff;
		border-radius: 10rpx;
		width: 75rpx;
		text-align: center;
	}

	.share-code {
		width: 80%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	/*分享操作*/
	.share {
		position: fixed;
		display: flex;
		bottom: 0;
		z-index: 9999;
		background-color: #fff;
		border-top-right-radius: 20rpx;
		border-top-left-radius: 20rpx;
		width: 100vw;
		height: 350rpx;
		justify-content: center;
		flex-direction: column;
	
		transition-property: transform;
		transition-duration: 0.1s;
		transition-timing-function: cubic-bezier(.5, .49, .57, 1.21);

		.share-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-bottom: 1rpx solid #f0f0f0;
			
		}
	}

	.share image {
		height: 127rpx;
		width: 125rpx;
		margin-bottom: 20rpx;
	}

	.share text {
		color: #303030;
		font-size: 30rpx;
		margin-bottom: 15rpx;
	}
</style>
